package com.gxa.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxa.common.utils.TPage;
import com.gxa.common.utils.Query;
import com.gxa.modules.sys.entity.User;
import com.gxa.modules.sys.mapper.UserMapper;
import com.gxa.modules.sys.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author zhuiyi
 * @since 2022-10-29 04:01:04
 */
@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User queryByUsername(String username) {
        return this.baseMapper.selectOne(new QueryWrapper<User>().eq(StringUtils.isNotEmpty(username),"username",username));
    }

    @Override
    public TPage queryByPage(Map<String, Object> searchMap) {
        //其他的查询参数
        String username = (String) searchMap.get("username");
        String id = (String) searchMap.get("id");
        String orderField = (String) searchMap.get("orderField");
        String order = (String) searchMap.get("order");
        log.info("------username----{}--id---{}--",username,id);
        IPage<User> oldPage = this.page(new Query<User>().getPage(searchMap),new QueryWrapper<User>()
                .likeRight(!StringUtils.isBlank(username),"username",username)
                .eq(!StringUtils.isBlank(id),"id",id)
        );
        return new TPage(oldPage);
    }
}
